<template>
	<div class="wrap">
		收货人信息<button class="btn" @click="usenew">使用新地址</button>
		<div class="cd" v-for="(item,index) in arr"><input type="radio" name="site"/><span>{{item.name}}</span> <span>{{item.site}}</span>电话<span>{{item.phone}}</span><div class="operation"><span>修改</span><span @click="remove(index)">删除</span></div></div>
	</div>
</template>

<script>
	export default{
		name:"oldsite",
		methods:{
			usenew(){
				window.location.href="#/newsite"
			},
			remove(index){
				var addressid = this.arr[index].id
				console.log(addressid)
				var _this=this;
				this.axios.get('/api/removeaddress',{params:{
					id:addressid
				}}).then(function(data){
					if(data.data.err==0){
						alert("删除失败")
					}else{
						_this.arr.splice(index,1)
						alert("删除成功")
					}
				})
			}
		},
		data(){
			return{
				arr:[]
			}
		},
		created(){
			var _this = this;
			this.axios.get('/api/getaddress').then(function(data){
				if(data.data.err==0){
					alert("错误")
				}else{
					console.log(data.data)
					_this.arr = data.data
				}
			})
		}
	}
</script>

<style scoped>
	.wrap{
		width: 1280px;
		margin: 0 auto;
	}
	.btn{
		color: white;
		background-color: #f08200;
		line-height: 30px;
		border-radius: 4px;
		float: right;
		width: 90px;
	}
	.cd{
		margin-top: 30px;
		line-height: 40px;
		background-color: #f4fff2;
	}
	.cd>span{
		margin: 20px;
		font-size: 16px;
	}
	.operation{
		color:green;
		float:right;
		display: inline-block;
	}
	.operation span{
		margin-right: 20px;
		
	}
</style>